from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
import time

from osv import fields, osv
from tools.translate import _
import decimal_precision as dp
import netsvc


class send_email_user(osv.osv):
    _name = "send.email.user"
    _description = "Send Email User"
    _columns = {
        'name': fields.char('Name', size=64, invisible=True),
        'company_id': fields.many2one('res.company', 'Company'),
        'user_id': fields.many2one('res.users', 'User'),
        'user_email': fields.char('Email', size=64),
    }

    def onchange_company_id(self, cr, uid, ids, company_id):
        v = {}
        res_user = self.pool.get('res.users')
        if company_id:
            lst_users = res_user.search(cr, uid, [('company_ids', '=', company_id)])
        return {'domain': {'user_id': [('id', 'in', lst_users)]}}

    def onchange_user_id(self, cr, uid, ids, user_id):
        v = {}
        res_user = self.pool.get('res.users')
        if user_id:
            user = res_user.browse(cr, uid, user_id)
            v['user_email'] = user.user_email
            v['name'] = user.user_email
            v['company_id'] = user.company_id.id
        return {'value': v}


send_email_user()
